package com.qm.model;

import java.util.ArrayList;
import java.util.Random;

import org.junit.Test;

public class TopicTest {

	private Integer tid;// 这道题在数据库中的ID
	private Integer tcourseCode;// 所属课程代码
	private String ttopicType;// 题目类型，单选或者是判断
	private String ttopic;// 题干
	private ArrayList<String> ansList;
	private Integer tcorrectIndex;

	private String tanswerAnalysis;// 答案解析

	public Integer getTid() {
		return tid;
	}

	public void setTid(Integer tid) {
		this.tid = tid;
	}

	public Integer getTcourseCode() {
		return tcourseCode;
	}

	public void setTcourseCode(Integer tcourseCode) {
		this.tcourseCode = tcourseCode;
	}

	public String getTtopicType() {
		return ttopicType;
	}

	public void setTtopicType(String ttopicType) {
		this.ttopicType = ttopicType;
	}

	public String getTtopic() {
		return ttopic;
	}

	public void setTtopic(String ttopic) {
		this.ttopic = ttopic;
	}

	public String getTanswerAnalysis() {
		return tanswerAnalysis;
	}

	public void setTanswerAnalysis(String tanswerAnalysis) {
		this.tanswerAnalysis = tanswerAnalysis;
	}

	public ArrayList<String> getAnsList() {
		return ansList;
	}

	public void setAnsList(ArrayList<String> ansList) {
		this.ansList = ansList;
	}

	public Integer getTcorrectIndex() {
		return tcorrectIndex;
	}

	public void setTcorrectIndex(Integer tcorrectIndex) {
		this.tcorrectIndex = tcorrectIndex;
	}

	public TopicTest(Topic topic) {
		this.tanswerAnalysis = topic.getTanswerAnalysis();
		this.tcourseCode = topic.getTcourseCode();
		this.tid = topic.getTid();
		this.ttopic = topic.getTtopic();
		this.ttopicType = topic.getTtopicType();
		this.ansList=new ArrayList<>();
		int []a=getSequence(4);
		for(int i=0;i<4;i++){
			switch (a[i]) {
			case 0:
				this.ansList.add(topic.getTcorrect());
				this.tcorrectIndex=i;
				break;
			case 1:
				this.ansList.add(topic.getTmistake1());
				break;
			case 2:
				this.ansList.add(topic.getTmistake2());
				break;
			case 3:
				this.ansList.add(topic.getTmistake3());
				break;
			default:
				break;
			}
		}
		
	}
    /**
     * 对给定数目的自0开始步长为1的数字序列进行乱序
     * @param no 给定数目
     * @return 乱序后的数组
     */
    public static int[] getSequence(int no) {
        int[] sequence = new int[no];
        for(int i = 0; i < no; i++){
            sequence[i] = i;
        }
        Random random = new Random();
        for(int i = 0; i < no; i++){
            int p = random.nextInt(no);
            int tmp = sequence[i];
            sequence[i] = sequence[p];
            sequence[p] = tmp;
        }
        random = null;
        return sequence;
    }
}
